package com.jr.controller;

import com.jr.entity.Enterprise;
import com.jr.entity.Post;
import com.jr.service.EnterpriseService;
import com.jr.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

@Controller
public class DemoController {
    @Autowired
    private PostService postService;
    @Autowired
    private EnterpriseService enterpriseService;

    @RequestMapping("/job_info")
    public ModelAndView findPostByid(Integer pid,Integer uid){

        Post post = postService.selectByPid(pid);
        int eid=post.getEid();
        Enterprise enterprise = enterpriseService.selectEByEid(eid);

        ModelAndView mv=new ModelAndView();
        mv.setViewName("job_info.html");
        mv.addObject("post",post);
        mv.addObject("enterprise",enterprise);
        mv.addObject("uid",uid);
        return mv;

    }
    @RequestMapping("/company")
    public ModelAndView findCompanyByid(Integer pid,Integer uid){

        Post post = postService.selectByPid(pid);
        int eid=post.getEid();
        Enterprise enterprise = enterpriseService.selectEByEid(eid);
        ArrayList<Post> posts = postService.SelectPostsByPid(eid);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("company.html");
        mv.addObject("post",post);
        mv.addObject("posts",posts);
        mv.addObject("enterprise",enterprise);
        mv.addObject("uid",uid);

        return mv;

    }


}
